<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="中层号" prop="mid">
        <el-input
          v-model="queryParams.mid"
          placeholder="请输入中层号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备编号" prop="dtu">
        <el-input
          v-model="queryParams.dtu"
          placeholder="请输入设备编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机器名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入机器名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车速" prop="speed">
        <el-input
          v-model="queryParams.speed"
          placeholder="请输入车速"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="当前轴长" prop="beamLength">
        <el-input
          v-model="queryParams.beamLength"
          placeholder="请输入当前轴长"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="当前回潮率" prop="mRate">
        <el-input
          v-model="queryParams.mRate"
          placeholder="请输入当前回潮率"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="卷绕张力设定" prop="windTension">
        <el-input
          v-model="queryParams.windTension"
          placeholder="请输入卷绕张力设定"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="压浆力1速" prop="pressSpeed1">
        <el-input
          v-model="queryParams.pressSpeed1"
          placeholder="请输入压浆力1速"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="压浆力2速" prop="pressSpeed2">
        <el-input
          v-model="queryParams.pressSpeed2"
          placeholder="请输入压浆力2速"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="压浆力高压" prop="pressLow">
        <el-input
          v-model="queryParams.pressLow"
          placeholder="请输入压浆力高压"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="压浆力低压" prop="pressHigh">
        <el-input
          v-model="queryParams.pressHigh"
          placeholder="请输入压浆力低压"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="浆槽温度" prop="temperature">
        <el-input
          v-model="queryParams.temperature"
          placeholder="请输入浆槽温度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="伸长率-牵引-合并烘筒" prop="sFrontDry">
        <el-input
          v-model="queryParams.sFrontDry"
          placeholder="请输入伸长率-牵引-合并烘筒"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="伸长率-合并-预烘筒" prop="sDryPredry">
        <el-input
          v-model="queryParams.sDryPredry"
          placeholder="请输入伸长率-合并-预烘筒"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="伸长率-合并-上浆" prop="sPredrySize">
        <el-input
          v-model="queryParams.sPredrySize"
          placeholder="请输入伸长率-合并-上浆"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="伸长率-上浆-喂入" prop="sSizeDraw">
        <el-input
          v-model="queryParams.sSizeDraw"
          placeholder="请输入伸长率-上浆-喂入"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="烘筒温度1" prop="tDry1">
        <el-input
          v-model="queryParams.tDry1"
          placeholder="请输入烘筒温度1"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="烘筒温度1" prop="tDry2">
        <el-input
          v-model="queryParams.tDry2"
          placeholder="请输入烘筒温度1"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="烘筒温度1" prop="tDry3">
        <el-input
          v-model="queryParams.tDry3"
          placeholder="请输入烘筒温度1"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="烘筒温度1" prop="tDry4">
        <el-input
          v-model="queryParams.tDry4"
          placeholder="请输入烘筒温度1"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="烘筒温度1" prop="tDry5">
        <el-input
          v-model="queryParams.tDry5"
          placeholder="请输入烘筒温度1"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="烘筒温度1" prop="tDry6">
        <el-input
          v-model="queryParams.tDry6"
          placeholder="请输入烘筒温度1"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="烘筒温度1" prop="tDry7">
        <el-input
          v-model="queryParams.tDry7"
          placeholder="请输入烘筒温度1"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="烘筒温度1" prop="tDry8">
        <el-input
          v-model="queryParams.tDry8"
          placeholder="请输入烘筒温度1"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="烘筒温度1" prop="tDry9">
        <el-input
          v-model="queryParams.tDry9"
          placeholder="请输入烘筒温度1"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="烘筒温度1" prop="tDry10">
        <el-input
          v-model="queryParams.tDry10"
          placeholder="请输入烘筒温度1"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="烘筒温度1" prop="tDry11">
        <el-input
          v-model="queryParams.tDry11"
          placeholder="请输入烘筒温度1"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="烘筒温度1" prop="tDry12">
        <el-input
          v-model="queryParams.tDry12"
          placeholder="请输入烘筒温度1"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="烘筒温度13" prop="tDry13">
        <el-input
          v-model="queryParams.tDry13"
          placeholder="请输入烘筒温度13"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="烘筒温度14" prop="tDry14">
        <el-input
          v-model="queryParams.tDry14"
          placeholder="请输入烘筒温度14"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间" prop="lastupdate">
        <el-date-picker clearable size="small"
          v-model="queryParams.lastupdate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['mes:history:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['mes:history:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['mes:history:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['mes:history:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="historyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="中层号" align="center" prop="mid" />
      <el-table-column label="设备编号" align="center" prop="dtu" />
      <el-table-column label="机器名" align="center" prop="name" />
      <el-table-column label="车速" align="center" prop="speed" />
      <el-table-column label="当前轴长" align="center" prop="beamLength" />
      <el-table-column label="当前回潮率" align="center" prop="mRate" />
      <el-table-column label="卷绕张力设定" align="center" prop="windTension" />
      <el-table-column label="压浆力1速" align="center" prop="pressSpeed1" />
      <el-table-column label="压浆力2速" align="center" prop="pressSpeed2" />
      <el-table-column label="压浆力高压" align="center" prop="pressLow" />
      <el-table-column label="压浆力低压" align="center" prop="pressHigh" />
      <el-table-column label="浆槽温度" align="center" prop="temperature" />
      <el-table-column label="伸长率-牵引-合并烘筒" align="center" prop="sFrontDry" />
      <el-table-column label="伸长率-合并-预烘筒" align="center" prop="sDryPredry" />
      <el-table-column label="伸长率-合并-上浆" align="center" prop="sPredrySize" />
      <el-table-column label="伸长率-上浆-喂入" align="center" prop="sSizeDraw" />
      <el-table-column label="烘筒温度1" align="center" prop="tDry1" />
      <el-table-column label="烘筒温度1" align="center" prop="tDry2" />
      <el-table-column label="烘筒温度1" align="center" prop="tDry3" />
      <el-table-column label="烘筒温度1" align="center" prop="tDry4" />
      <el-table-column label="烘筒温度1" align="center" prop="tDry5" />
      <el-table-column label="烘筒温度1" align="center" prop="tDry6" />
      <el-table-column label="烘筒温度1" align="center" prop="tDry7" />
      <el-table-column label="烘筒温度1" align="center" prop="tDry8" />
      <el-table-column label="烘筒温度1" align="center" prop="tDry9" />
      <el-table-column label="烘筒温度1" align="center" prop="tDry10" />
      <el-table-column label="烘筒温度1" align="center" prop="tDry11" />
      <el-table-column label="烘筒温度1" align="center" prop="tDry12" />
      <el-table-column label="烘筒温度13" align="center" prop="tDry13" />
      <el-table-column label="烘筒温度14" align="center" prop="tDry14" />
      <el-table-column label="更新时间" align="center" prop="lastupdate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastupdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['mes:history:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['mes:history:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改浆纱历史记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="中层号" prop="mid">
          <el-input v-model="form.mid" placeholder="请输入中层号" />
        </el-form-item>
        <el-form-item label="设备编号" prop="dtu">
          <el-input v-model="form.dtu" placeholder="请输入设备编号" />
        </el-form-item>
        <el-form-item label="机器名" prop="name">
          <el-input v-model="form.name" placeholder="请输入机器名" />
        </el-form-item>
        <el-form-item label="车速" prop="speed">
          <el-input v-model="form.speed" placeholder="请输入车速" />
        </el-form-item>
        <el-form-item label="当前轴长" prop="beamLength">
          <el-input v-model="form.beamLength" placeholder="请输入当前轴长" />
        </el-form-item>
        <el-form-item label="当前回潮率" prop="mRate">
          <el-input v-model="form.mRate" placeholder="请输入当前回潮率" />
        </el-form-item>
        <el-form-item label="卷绕张力设定" prop="windTension">
          <el-input v-model="form.windTension" placeholder="请输入卷绕张力设定" />
        </el-form-item>
        <el-form-item label="压浆力1速" prop="pressSpeed1">
          <el-input v-model="form.pressSpeed1" placeholder="请输入压浆力1速" />
        </el-form-item>
        <el-form-item label="压浆力2速" prop="pressSpeed2">
          <el-input v-model="form.pressSpeed2" placeholder="请输入压浆力2速" />
        </el-form-item>
        <el-form-item label="压浆力高压" prop="pressLow">
          <el-input v-model="form.pressLow" placeholder="请输入压浆力高压" />
        </el-form-item>
        <el-form-item label="压浆力低压" prop="pressHigh">
          <el-input v-model="form.pressHigh" placeholder="请输入压浆力低压" />
        </el-form-item>
        <el-form-item label="浆槽温度" prop="temperature">
          <el-input v-model="form.temperature" placeholder="请输入浆槽温度" />
        </el-form-item>
        <el-form-item label="伸长率-牵引-合并烘筒" prop="sFrontDry">
          <el-input v-model="form.sFrontDry" placeholder="请输入伸长率-牵引-合并烘筒" />
        </el-form-item>
        <el-form-item label="伸长率-合并-预烘筒" prop="sDryPredry">
          <el-input v-model="form.sDryPredry" placeholder="请输入伸长率-合并-预烘筒" />
        </el-form-item>
        <el-form-item label="伸长率-合并-上浆" prop="sPredrySize">
          <el-input v-model="form.sPredrySize" placeholder="请输入伸长率-合并-上浆" />
        </el-form-item>
        <el-form-item label="伸长率-上浆-喂入" prop="sSizeDraw">
          <el-input v-model="form.sSizeDraw" placeholder="请输入伸长率-上浆-喂入" />
        </el-form-item>
        <el-form-item label="烘筒温度1" prop="tDry1">
          <el-input v-model="form.tDry1" placeholder="请输入烘筒温度1" />
        </el-form-item>
        <el-form-item label="烘筒温度1" prop="tDry2">
          <el-input v-model="form.tDry2" placeholder="请输入烘筒温度1" />
        </el-form-item>
        <el-form-item label="烘筒温度1" prop="tDry3">
          <el-input v-model="form.tDry3" placeholder="请输入烘筒温度1" />
        </el-form-item>
        <el-form-item label="烘筒温度1" prop="tDry4">
          <el-input v-model="form.tDry4" placeholder="请输入烘筒温度1" />
        </el-form-item>
        <el-form-item label="烘筒温度1" prop="tDry5">
          <el-input v-model="form.tDry5" placeholder="请输入烘筒温度1" />
        </el-form-item>
        <el-form-item label="烘筒温度1" prop="tDry6">
          <el-input v-model="form.tDry6" placeholder="请输入烘筒温度1" />
        </el-form-item>
        <el-form-item label="烘筒温度1" prop="tDry7">
          <el-input v-model="form.tDry7" placeholder="请输入烘筒温度1" />
        </el-form-item>
        <el-form-item label="烘筒温度1" prop="tDry8">
          <el-input v-model="form.tDry8" placeholder="请输入烘筒温度1" />
        </el-form-item>
        <el-form-item label="烘筒温度1" prop="tDry9">
          <el-input v-model="form.tDry9" placeholder="请输入烘筒温度1" />
        </el-form-item>
        <el-form-item label="烘筒温度1" prop="tDry10">
          <el-input v-model="form.tDry10" placeholder="请输入烘筒温度1" />
        </el-form-item>
        <el-form-item label="烘筒温度1" prop="tDry11">
          <el-input v-model="form.tDry11" placeholder="请输入烘筒温度1" />
        </el-form-item>
        <el-form-item label="烘筒温度1" prop="tDry12">
          <el-input v-model="form.tDry12" placeholder="请输入烘筒温度1" />
        </el-form-item>
        <el-form-item label="烘筒温度13" prop="tDry13">
          <el-input v-model="form.tDry13" placeholder="请输入烘筒温度13" />
        </el-form-item>
        <el-form-item label="烘筒温度14" prop="tDry14">
          <el-input v-model="form.tDry14" placeholder="请输入烘筒温度14" />
        </el-form-item>
        <el-form-item label="更新时间" prop="lastupdate">
          <el-date-picker clearable size="small"
            v-model="form.lastupdate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择更新时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listHistory, getHistory, delHistory, addHistory, updateHistory, exportHistory } from "@/api/mes/history";

export default {
  name: "History",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 浆纱历史记录表格数据
      historyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mid: null,
        dtu: null,
        name: null,
        speed: null,
        beamLength: null,
        mRate: null,
        windTension: null,
        pressSpeed1: null,
        pressSpeed2: null,
        pressLow: null,
        pressHigh: null,
        temperature: null,
        sFrontDry: null,
        sDryPredry: null,
        sPredrySize: null,
        sSizeDraw: null,
        tDry1: null,
        tDry2: null,
        tDry3: null,
        tDry4: null,
        tDry5: null,
        tDry6: null,
        tDry7: null,
        tDry8: null,
        tDry9: null,
        tDry10: null,
        tDry11: null,
        tDry12: null,
        tDry13: null,
        tDry14: null,
        lastupdate: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询浆纱历史记录列表 */
    getList() {
      this.loading = true;
      listHistory(this.queryParams).then(response => {
        this.historyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        mid: null,
        dtu: null,
        name: null,
        speed: null,
        beamLength: null,
        mRate: null,
        windTension: null,
        pressSpeed1: null,
        pressSpeed2: null,
        pressLow: null,
        pressHigh: null,
        temperature: null,
        sFrontDry: null,
        sDryPredry: null,
        sPredrySize: null,
        sSizeDraw: null,
        tDry1: null,
        tDry2: null,
        tDry3: null,
        tDry4: null,
        tDry5: null,
        tDry6: null,
        tDry7: null,
        tDry8: null,
        tDry9: null,
        tDry10: null,
        tDry11: null,
        tDry12: null,
        tDry13: null,
        tDry14: null,
        lastupdate: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加浆纱历史记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getHistory(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改浆纱历史记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateHistory(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addHistory(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除浆纱历史记录编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delHistory(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有浆纱历史记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportHistory(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
